package com.web.controller;

import com.web.entity.PageVO;
import com.web.entity.Student;
import com.web.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lenovo
 * @Description
 * @Date2025-3-21 14:30
 */
@CrossOrigin //解决跨域问题
@RestController
public class StudentController {

    @Resource
    private StudentService studentService;

    @RequestMapping("/findStudentPage")
    public ResponseResult findStudentPage(@RequestParam(name = "current",required = false,defaultValue = "1")int current,
                                          @RequestParam(name = "pageSize",required = false,defaultValue = "10")int pageSize){
        PageVO page = studentService.findStudentPage(current, pageSize);
        return new ResponseResult(200,"OK",page);
    }

    @RequestMapping("/insertStudent")
    public ResponseResult addStudent(Student student){
        studentService.addStudent(student);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping("/updateStudent")
    public ResponseResult updateStudent(Student student){
        studentService.updateStudent(student);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping("/deleteStudent")
    public ResponseResult deleteStudent(int id){
        studentService.removeStudent(id);
        return new ResponseResult(200,"OK",null);
    }

}